import { createStore, applyMiddleware } from 'redux'
import logger from 'redux-logger';
import thunk from 'redux-thunk';
import { ALLSTATE, ALLACTION, SETNAME, SETLIST } from '../types/store.d'
const initialState = {
    list: [],
    name: ""
}

const reducer = (state: ALLSTATE = initialState, { type, payload }: ALLACTION) => {
    switch (type) {
        case SETLIST:
            state.list = payload
            return { ...state }
        case SETNAME:
            state.name = payload
            return { ...state }
        default:
            return state
    }
}

const store = createStore(reducer, applyMiddleware(logger, thunk))

export default store